package org.example.work2.tcc.order.controller;


import io.seata.rm.tcc.api.BusinessActionContext;
import lombok.extern.slf4j.Slf4j;
import org.example.work2.tcc.order.service.OrderAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author xh
 * @date 2023/04/03
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {


    @Autowired
    private OrderAction orderAction;

    @PostMapping("/create")
    public boolean createOrder(@RequestBody BusinessActionContext actionContext,
                               @RequestParam("id") Long id,
                               @RequestParam("accountCode") String accountCode,
                               @RequestParam("productId") String productId,
                               @RequestParam("productCounts") Integer productCounts,
                               @RequestParam("totalPrice") Integer totalPrice) throws Exception {
        log.info("[createOrder] 收到下单请求, 用户:{}, 商品id:{}, 数量:{}", accountCode, productId, productCounts);
        return orderAction.createOrderPrepare(actionContext, id, accountCode, productId, productCounts, totalPrice);
    }

}
